Better handling of UTF-8 paths (#87)
authorViet-Tam Luu <viettaml@google.com>
Mon, 4 Dec 2017 21:54:19 +0000 (13:54 -0800)
committertsteven4 <tsteven4@users.noreply.github.com>
Mon, 4 Dec 2017 21:54:19 +0000 (14:54 -0700)
commite4bced74359bffbea7da9c94ceb2858488f1fac4
tree3a214210fbf602a0e83b1d196e826891cf3ac62b
parent9cc21d2f9f07775f4ca99eb92c6dc4cf4e6bdccf
Better handling of UTF-8 paths (#87)

* Better handling of UTF-8 paths

Remove gpsbabel calls to qPrintable which destroys non-ANSI path names on Windows. Replace with QString::toUtf8() and modify low-level file handling code to use _wfopen() and other wide-char functions on Windows to support non-ASCII paths. (I did an experiment to convince myself that fopen() doesn't do UTF-8, and that _wfopen() correctly creates a file with a non-ASCII filename starting from a UTF-8 name.) Add ufopen() function as a UTF-8 wrapper for fopen(). Change inifile_init() filename argument type to QString.

Leave serial port paths alone ("if your serial port path has non-ANSI characters, you're going to have a bad time").

* Fix valgrind mismatched free/malloc error.

* Correctly encode output paths in native locale on non-Windows

On Mac/Linux, convert output file path from internal UTF-8 to local encoding (which may be UTF-8 or something else) when creating the file. Fixes test_encoding failure.

* Support Unicode paths for .gz files on Windows

Use zlib's Windows-specific gzopen_w() to support Unicode paths.

* Convert UTF-8 to local encoding when opening gzip file on non-Windows

This should fix the test_encoding failure on Travis-CI.

Also, change Windows side to manually allocating wchar_t array; although a bit less elegant, it's very localized and avoids introducing a whole new dependency on std::wstring.

* Use explicit char* to QString conversion in qPrintable

The implicit conversion works, but I prefer the an explicit one (if only as a reminder that we should convert all internal strings to QString).

* Add comment to QString-to-wchar_t[] conversion

... since it may not be immediately obvious what that line of code does.

* Fix merge conflict resolution error

* Fix merge conflict (again)

* Revert shape.cc

* Update gbfile.cc

* Update mkt_logger.cc to use QString tempfile paths.

* Change ufopen() to take QString filename argument.
Where converting from char*, use an explicit QString::fromUtf8() conversion rather than the implicit QString(const char*) constructor.

* Use QFile::exists() and QFile::open() rather than ufopen() to verify a file exists and can be opened.

* Remove redundant call to QFile::exists(). Trivial include cleanup in main.cc.

* Remove superfluous QVector include.

* add newline at EOF.
16 files changed:
bcr.cc
defs.h
exif.cc
explorist_ini.cc
garmin_device_xml.cc
gbfile.cc
ggv_ovl.cc
inifile.cc
inifile.h
kml.cc
main.cc
mtk_logger.cc
raymarine.cc
util.cc
v900.cc
wbt-200.cc